package com.crealth.memcached;

import java.util.List;

import com.crealth.db.ConsumerDb;
import com.crealth.model.ConsumerPolicyModel;

public class ConsumerPolicyCached {
	private static final String policyKeyPrefix = "policy_csmid_";
	
	@SuppressWarnings("unchecked")
	public static List<ConsumerPolicyModel> selectConsumerPolicy(int consumerID) {
		String key = policyKeyPrefix + consumerID;
		Object obj = MemcachedMgr.cachedClient.get(key);
		List<ConsumerPolicyModel> policyls = null;
		if (obj != null) {
			policyls = (List<ConsumerPolicyModel>)obj;
		}
		else {
			policyls = ConsumerDb.selectConsumerPolicy(consumerID);
			if (policyls != null) {
				MemcachedMgr.cachedClient.set(key, policyls);
			}
		}
		
		return policyls;
	}
	
	public static void deleteCached(int consumerID) {
		String key = policyKeyPrefix + consumerID;
		MemcachedMgr.cachedClient.delete(key);
	}
	
}
